package top.hmtools.compressor;

import org.mozilla.javascript.ErrorReporter;
import org.mozilla.javascript.EvaluatorException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class HmErrorReporter implements ErrorReporter {

	private final Logger logger = LoggerFactory.getLogger(HmErrorReporter.class);

	@Override
	public void warning(String message, String sourceName, int line, String lineSource, int lineOffset) {
		System.err.println("\n[WARNING] in " + sourceName);
		if (line < 0) {
			System.err.println("  " + message);
		} else {
			System.err.println("  " + line + ':' + lineOffset + ':' + message);
		}
	}

	@Override
	public void error(String message, String sourceName, int line, String lineSource, int lineOffset) {
		System.err.println("[ERROR] in " + sourceName);
		if (line < 0) {
			System.err.println("  " + message);
		} else {
			System.err.println("  " + line + ':' + lineOffset + ':' + message);
		}
	}

	@Override
	public EvaluatorException runtimeError(String message, String sourceName, int line, String lineSource,
			int lineOffset) {
		error(message, sourceName, line, lineSource, lineOffset);
		return new EvaluatorException(message);
	}

}
